﻿using System;
using System.Collections.Generic;
using System.Linq;
using Enums;
using XF.ExControls;
using XF.Common;
using System.Drawing;
using XF.BLL;

namespace BabySwim
{
    public partial class FrmRecharge : XFFormEx
    {
        private int familyId;
        private readonly XF.BLL.Base_Family bllFamily = new Base_Family();
        private readonly XF.BLL.Course_Recharge bllRecharge = new Course_Recharge();
        public FrmRecharge(int _familyId)
        {
            InitializeComponent();
            familyId = _familyId;
        }

        private void tsBtnSure_Click(object sender, EventArgs e)
        {
            XF.Model.Course_Recharge model = new XF.Model.Course_Recharge();
            model.FamilyId = familyId;
            model.CourseCount = Convert.ToInt32(nudRechargeCount.Value);
            model.TotlePrice = 0;
            if(bllRecharge.Add(model)>=0)
            {
                QQMessageBox.Show(
                this,
                MessageText.TIP_SUCCESS_RECHARGE,
                MessageText.MESSAGEBOX_CAPTION_TIP,
                QQMessageBoxIcon.OK,
                QQMessageBoxButtons.OK);
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                QQMessageBox.Show(
                this,
                MessageText.RECHARGE_ERROR,
                MessageText.MESSAGEBOX_CAPTION_ERROR,
                QQMessageBoxIcon.Information,
                QQMessageBoxButtons.OK);
            }
        }

        private void tsBtnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmCustomerCard_Load(object sender, EventArgs e)
        {
            this.Icon = ConfigSetting.ProjectIcon;
            this.TextForeColor = ConfigSetting.TextForeColor;
            XF.Model.Base_Family model = bllFamily.GetModel(familyId);
            if(model != null)
            {
                tbCode.Text = model.FamilyCode;
                tbName.Text = model.FamilyName;
                tbCourseCount.Text = model.CourseCount.ToString();
            }
        }
    }
}
